package com.zrf.testchatgpt.handler;

import com.zrf.testchatgpt.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class MyExceptionHandler {
    @ExceptionHandler(value =NullPointerException.class)
    public Result exceptionHandler(NullPointerException e){
        log.info("异常捕获:空指针问题");
        return Result.builder().code("500").msg(e.getMessage()).build();
    }
    @ExceptionHandler(value = UnknownAccountException.class)
    public Result unknown(UnknownAccountException e){
        log.info("异常捕获:unknown问题");
        return Result.builder().code("500").msg(e.getMessage()).build();
    }
    @ExceptionHandler(value = AuthorizationException.class)
    public Result authorizationException(AuthorizationException e){
        log.info("异常捕获:权限不足问题");
        return Result.builder().code("403").msg("你没有权限访问").build();
    }
    @ExceptionHandler(value = HttpHostConnectException.class)
    public Result authorizationException(HttpHostConnectException e){
        log.info("异常捕获:http请求问题");
        return Result.builder().code("500").msg("请求失败").build();
    }
}
